package com.wenjie.controller.sys;

import com.wenjie.original.entity.common.vo.RestBaseVo;
import com.wenjie.original.entity.vo.SysLogOper.SysLogOperUpOrAddVo;
import com.wenjie.original.entity.vo.SysLogOper.SysLogOperVo;
import com.wenjie.original.service.ISysLogOperService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.wenjie.original.entity.table.SysLogOperTableDef.SYS_LOG_OPER;

@RestController
@RequestMapping("/api/sysLogOper")
public class SysLogOperController {

    @Autowired
    private ISysLogOperService sysLogOperService;

    @ApiOperation("查询接口")
    @PostMapping("/list")
    public RestBaseVo<SysLogOperVo.ResVo> list(@RequestBody @Validated SysLogOperVo.SelVo selVo) {
        if (selVo.getCreateDateStart() == null && selVo.getCreateDateEnd() == null) {
            return sysLogOperService.list(selVo, SysLogOperVo.ResVo.class);
        } else {
            return sysLogOperService.list(selVo, SYS_LOG_OPER.CREATE_TIME.between(selVo.getCreateDateStart(), selVo.getCreateDateEnd()), SysLogOperVo.ResVo.class);
        }
    }

    @ApiOperation("添加接口")
    @PostMapping("/add")
    public void add(@RequestBody @Validated SysLogOperUpOrAddVo.AddVo addVo) {
        sysLogOperService.save(addVo);
    }

    @ApiOperation("修改接口")
    @PostMapping("/up")
    public void up(@RequestBody @Validated SysLogOperUpOrAddVo.UpVo upVo) {
        sysLogOperService.updateById(upVo);
    }


}
